package lion.web.taglib.fn;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import lion.dev.net.IP;
import lion.dev.net.IPBase;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;

/**
 * @author lion
 * @email hl_0074@sina.com
 * @date 2014年5月22日
 */
public class PageFunctions {

	public static String encode(String key) {

		if (StringUtils.isBlank(key)) { return ""; }

		try {
			return URLEncoder.encode(key, "UTF-8");
		} catch (UnsupportedEncodingException e) {
		}
		return "";
	}

	public static String ip(String sip) {

		if (StringUtils.isBlank(sip)) { return ""; }
		IP ip = IPBase.query(sip);
		return ip.getArea() + "-" + ip.getPosition();
	}

	public static String iparea(String sip) {

		if (StringUtils.isBlank(sip)) { return ""; }
		IP ip = IPBase.query(sip);
		return ip.getArea();
	}

	public static boolean contains(String src, String t, String split) {
		if (StringUtils.isBlank(split)) {
			split = ",";
		}
		String[] arr = src.split(split);
		return ArrayUtils.contains(arr, t);
	}

}
